<template>
  <div class="app-container">
    <h4 class="form-header h4">基本信息</h4>
    <el-form ref="form" :model="form" label-width="80px">
      <el-row>
        <el-col :span="8" :offset="2">
          <el-form-item label="小说名称" prop="nickName">
            <el-input v-model="form.novelName" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="2">
          <el-form-item label="小说分类" prop="userName">
            <el-input  v-model="form.currentCategory" disabled />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <h4 class="form-header h4">分类列表</h4>

    <el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="索引" type="index" :index="myIndex"/>
      <el-table-column label="分类名" prop="name" :show-overflow-tooltip="true" />
      <el-table-column label="频道" prop="workDirection" :formatter="formatter" :show-overflow-tooltip="true" />
      <el-table-column label="排序" prop="sort" :show-overflow-tooltip="true" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="warning"
            icon="el-icon-edit"
            v-hasPermi="['system:role:remove']"
            @click="updateCategory(scope.row)"
          >修改分类</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
<!--    <select-user ref="select" :bookId="queryParams.bookId" @ok="handleQuery" />-->
  </div>
</template>

<script>
import {currentCategory,unaddCategory,updateCategory} from "@/api/sys/novel";
//import selectUser from "./selectUser";

export default {
  name: "bookCategory",
  dicts: ['sys_normal_disable'],
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中用户组
      userIds: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      categoryList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bookId: undefined,
      },
      form:{
        bookId:'',
        novelName:'',
        currentCategory:''
      }
    };
  },
  created() {
    const bookId = this.$route.params.bookId;
    if (bookId) {
      this.queryParams.bookId = bookId;
      this.getList();
    }
  },
  methods: {
    /** 查询授权用户列表 */
    myIndex(index){
      return index+1
    },
    getList() {
      this.loading = true;
      unaddCategory(this.queryParams.bookId).then(response => {
          this.categoryList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
      currentCategory(this.queryParams.bookId).then(response =>{
        this.form.novelName=response.data.bookName
        this.form.currentCategory=response.data.catName
        this.form.bookId=response.data.id
      })
    },
    // 返回按钮
    handleClose() {
      const obj = { path: "/system/role" };
      this.$tab.closeOpenPage(obj);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId)
      this.multiple = !selection.length
    },
    /** 打开授权用户表弹窗 */
    openSelectUser() {
      this.$refs.select.show();
    },
    formatter(row){
      if (row.workDirection){
        return '女频'
      }else {
        return '男频'
      }
    },
    updateCategory(row){
      const query ={}
      query.id=this.form.bookId||undefined
      query.catId=row.id||undefined
      query.catName=row.name||undefined
      updateCategory(query).then(response=>{
        this.getList()
      })
    }
   /* /!** 取消授权按钮操作 *!/
    cancelAuthUser(row) {
      const roleId = this.queryParams.roleId;
      this.$modal.confirm('确认要取消该用户"' + row.userName + '"角色吗？').then(function() {
        return authUserCancel({ userId: row.userId, roleId: roleId });
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消授权成功");
      }).catch(() => {});
    },
    /!** 批量取消授权按钮操作 *!/
    cancelAuthUserAll(row) {
      const bookId = this.queryParams.bookId;
      const userIds = this.userIds.join(",");
      this.$modal.confirm('是否取消选中用户授权数据项？').then(function() {
        return authUserCancelAll({ bookId: bookId, userIds: userIds });
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消授权成功");
      }).catch(() => {});
    }*/
  }
};
</script>
